cmake_minimum_required(VERSION 3.0.2)
project(scout_mini_demo)

add_compile_options(-std=c++14)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  sensor_msgs
  geometry_msgs
  nav_msgs
  tf2
  tf2_ros
  diagnostic_msgs
)

find_package(ugv_sdk REQUIRED)

catkin_package()

include_directories(BEFORE
  include
  ${catkin_INCLUDE_DIRS}
  ${ugv_sdk_INCLUDE_DIRS}
  /usr/local/include
  /usr/include
  # 使用工作空间内的 ugv_sdk 源码（无需系统安装）
  ${CMAKE_CURRENT_SOURCE_DIR}/../../../ugv_sdk/include
)

# 链接到工作空间内 ugv_sdk 的本地构建目录（需先在该目录编出库）
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../ugv_sdk/build /usr/local/lib /usr/lib)

# 允许用环境变量覆盖 ugv_sdk 位置：UGV_SDK_DIR=/path/to/ugv_sdk
if(DEFINED ENV{UGV_SDK_DIR})
  message(STATUS "Using UGV_SDK_DIR=$ENV{UGV_SDK_DIR}")
  include_directories($ENV{UGV_SDK_DIR}/include)
  link_directories($ENV{UGV_SDK_DIR}/build)
endif()

# 自动探测头文件是否存在，便于排错
set(UGV_SDK_HINT ${CMAKE_CURRENT_SOURCE_DIR}/../../../ugv_sdk/include/ugv_sdk/mobile_robot/scout_robot.hpp)
if(EXISTS ${UGV_SDK_HINT})
  message(STATUS "Found ugv_sdk headers at: ${UGV_SDK_HINT}")
else()
  message(WARNING "ugv_sdk header not found at ${UGV_SDK_HINT}. If build fails, set UGV_SDK_DIR env or adjust include path.")
endif()

add_executable(scout_mini_node src/scout_mini_node.cpp)
target_link_libraries(scout_mini_node ${catkin_LIBRARIES} ${ugv_sdk_LIBRARIES})
if(TARGET ugv_sdk::ugv_sdk)
  target_link_libraries(scout_mini_node ugv_sdk::ugv_sdk)
endif()
# 本地构建的库名（若未找到导入目标时兜底）
target_link_libraries(scout_mini_node ugv_sdk)

install(TARGETS scout_mini_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY launch rviz
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)



